package com.myproject.thread;

public class ExceptionHandler implements Thread.UncaughtExceptionHandler {
    @Override
    public void uncaughtException(Thread t, Throwable e) {
        System.out.println(t.getName()+"抛出异常"+e+"而中断");
    }

    public static void main(String[] args) {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                if (3>1){
                    throw new RuntimeException("一场");
                }
            }
        });
        thread.setUncaughtExceptionHandler(new ExceptionHandler());
        thread.start();
    }
}
